<%@ page contentType="text/html; charset=utf-8" language="java"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>系统用户</title>
<link type="text/css" rel="stylesheet" href="/commonSys/css/index.css" />
<script language="javascript" src="/commonSys/js/jquery-1.7.1.min.js"></script>
<script language="javascript" src="/commonSys/js/lightbox/jquery.lightbox_me.js"></script>
<script language="javascript" src="/commonSys/js/validate.js"></script>
</head>
<body>
        <div class="right_main">
        	<!-- <div class="right_title">系统管理 >  用户管理</div> -->
            <div class="right_main_title_bg">
            	<s:form id="selectForm"  action="select" theme="simple">  
					<div class="right_main_padding_1">
						<span class="spanTxt">用户编号：</span>
                      	<s:textfield  name="vo.employeeNo" id="vo.employeeNo" theme="simple"  cssClass="inputText_1" maxlength= "20" /> 
						<span class="spanTxt">用户名：</span>
                        <s:textfield  name="vo.name" id="vo.name" theme="simple" cssClass="inputText_1" maxlength= "20" />
	                	&nbsp;&nbsp;&nbsp;&nbsp;
	                    <span class="btn_1 searchBtn"  id="selectButton" onclick="selectData();" ></span>
	                    &nbsp;&nbsp;&nbsp;&nbsp;<span class="default_btn_1" onclick="javascript:toInsertDiv();">添加</span>
	                    <span style="display: none"> 
							gotoPage<s:textfield name="gotoPage" id="gotoPage" /> 
							pageSize<s:textfield name="pageSize" id="pageSize" /> 
							firstPage<s:textfield name="firstPage" id="firstPage" /> 
							lastPage<s:textfield name="lastPage" id="lastPage" />
							nextPage<s:textfield name="nextPage" id="nextPage" />
							prePage<s:textfield name="prePage" id="prePage" /> 
							countPage<s:textfield name="countPage" id="countPage" />
							countData<s:textfield name="countData" id="countData" />
						</span>
                </div>
			    </s:form>
                <table class="table_1" cellpadding="0" cellspacing="1">
                	<tr class="th_bg">
                        <td>用户编号</td>
                        <td>用户名</td>
                        <td>操作</td>
                    </tr>
                 <s:iterator value="userList" status="st">  
                    <tr class="tr_1">
                        <td><s:property value="employeeNo"/></td>
                        <td><s:property value="name"/></td>
                       	<td>
                       		<s:if test="isRoot==0">
								<span class="default_btn_1"   onclick="openPage('/commonSys/manager/user/beforeSaveRole.shtml?id=<s:property value="id"/>');">设置角色</span>
								<span class="default_btn_1"   onclick="openPage('/commonSys/manager/role/beforeSavePrivilege.shtml?id=<s:property value="id"/>&type=1');">设置权限</span>
								<span class="default_btn_1"   onclick="deleteUser('<s:property value="id"/>');">删除</span>
							</s:if> 
							<s:else>根用户</s:else>
                 		</td>
                 	</tr>
				 </s:iterator>                    
                </table>
                <div class="page_div">
                    共 <span id="allcount"><s:property value="countData"/></span> 条记录 &nbsp;	每页 <span id="pagesize" ><s:property value="pageSize"/></span> 条记录&nbsp;
					共 <span id="pagecount" ><s:property value="countPage"/></span> 页&nbsp;
					第 <span id="pageno" ><s:property value="gotoPage"/></span> 页&nbsp;&nbsp;
					<input type="button" class="wbt" value="首页" onclick="if(g('gotoPage').value!=g('firstPage').value){g('gotoPage').value=g('firstPage').value;selectData();}else{alert('已经在首页');}"/>
					&nbsp;
					<input type="button" class="wbt" value="上一页" onclick="if(g('gotoPage').value!=g('firstPage').value){g('gotoPage').value=g('prePage').value;selectData();}else{alert('已经在首页');}" />
					&nbsp;
					<input type="button" class="wbt" value="下一页" onclick="if(g('gotoPage').value != g('countPage').value){g('gotoPage').value=g('nextPage').value;selectData();}else{alert('已经在末页');}" />
					&nbsp;
					<input type="button" class="wbt" value="末页" onclick="if(g('gotoPage').value != g('lastPage').value){g('gotoPage').value=g('lastPage').value;selectData();}else{alert('已经在末页');}" />
					&nbsp;&nbsp;
                    
            	</div>
            </div>
        </div>

<div id="SHOW_DIV_1" style="display:none;">
        <div class="show_main">
            <div class="title">编辑用户</div>
            <div class="content">
              <s:form id="insert-update-Form" name="insert-update-Form"  theme="simple">  
              	<input type="hidden" class="inputText_1" name="vo.id" id="vo.id"  />
                <ul>
                    <li>
                        <span class="spanTxt">用户名称：</span>
                        <input type="text" class="inputText_1" name="vo.name" id="vo.name"  maxlength="20"  />
                    </li>
                    <li>
                        <span class="spanTxt">用户编号：</span>
                        <input type="text" class="inputText_1" name="vo.employeeNo" id="vo.employeeNo" maxlength="10"  />
                    </li>
                    <li>
                        <span class="spanTxt">初始密码：</span>
                        <input type="password" class="inputText_1" name="vo.password" id="vo.password"  maxlength="15"  />
                    </li>
                </ul>
      			</s:form>
            </div>
            <div class="bottom">
                <span class="default_btn_1" id="insert-update-but"  onclick="insert();"   >确定</span>&nbsp;&nbsp;&nbsp;&nbsp;
                <span class="default_btn_1 close">取消</span>
            </div>
        </div>
	</div>
<script language="javascript">

	 function selectData()
	 {	
	 	$("#selectForm").submit();
	 }

	function toInsertDiv(){
		$("#SHOW_DIV_1").lightbox_me({
			 centered: false
			,modalCSS:{top:'20px'}
			,onClose:function(){clearFormValue('insert-update-Form');}
		});
		$('#insert-update-but').attr("onclick","insert();");
	}
	
	function insert(){
		var url = "/commonSys/manager/user/insert.shtml";
		var param = $("#insert-update-Form").serialize();
		$.post(url 
			,param 
				,function(rs) {
					if(rs.code==0){
						selectData();
					}else{
						alert('操作失败');
					}
				}
		   ,'json');
		
		clearFormValue('insert-update-Form');
	}

	function toUpdateDiv(id){
		$("#SHOW_DIV_1").lightbox_me({
			centered: false
			,modalCSS:{top:'20px'}
			,onLoad:function(){
				var url = "/commonSys/manager/user/selectuserById.shtml";
				var param = {id:id};
				$.post(url 
					,param 
						,function(rs) {
							if(rs.code==0){
								fillTemplateValue("insert-update-Form",rs.data);
							}
						}
				   ,'json');
			}
			,onClose:function(){clearFormValue('insert-update-Form');}
		});
	}
	

	function update(){
		var url = "/commonSys/manager/user/update.shtml";
		var param = $("#insert-update-Form").serialize();
		$.post(url 
			,param 
				,function(rs) {
					if(rs.code==0){
						selectData();
					}
				}
		   ,'json');
		
		clearFormValue('insert-update-Form');
	}
	
	function fillTemplateValue(boxId,json){
		var keys = new Array("id","name"); //这个要自定义
		for(var i=0;i<keys.length;i++){
			var e1 = $("#insert-update-Form [name*="+keys[i]+"]");
			if(e1.prop("nodeName")=="TEXTAREA"){
				e1.html(json[keys[i]]);
			}else if(e1.prop("nodeName")=="INPUT" || e1.prop("nodeName")=="SELECT" ){
				e1.val(json[keys[i]]);
			}
		}
		$('#insert-update-but').attr("onclick","update();");
	}

	function clearFormValue(fId){
		$('#'+fId)[0].reset();
	}
	
	
	function openPage(url){
		window.open(url,'newwindow','height=500,width=576,top=200,left=350,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no') ;
	}

	function deleteUser(id){
		var url = "/commonSys/manager/user/delete.shtml";
		var param = {id:id};
		$.post(url 
			,param 
				,function(rs) {
					if(rs.code==0){
						selectData();
					}
				}
		   ,'json');
	}


</script>             
</body>
</html>
